// Import the FileWriter class
// Import the File class
// Import this class to handle errors
import java.io.*;  
import java.awt.event.*;
import java.util.Scanner; // Import the Scanner class to read text files
import javax.swing.*;  
import java.awt.*;     
import java.io.*;  
public class notes {  
public static void main(String[] args) {  
JFrame f=new JFrame();//creating instance of JFrame  
Image icon = Toolkit.getDefaultToolkit().getImage("notepad.png");  
String applicationTitle="Notes";    
f.setTitle(applicationTitle);
f.setIconImage(icon);    
          
JButton b=new JButton("Save");//creating instance of JButton  
b.setBounds(0,0,199, 40);//x axis, y axis, width, height  
JButton b1=new JButton("Load");//creating instance of JButton  
b1.setBounds(199,0,199, 40);//x axis, y axis, width, height  
JTextField t1;  
t1=new JTextField("Filename.txt");  
t1.setBounds(0,40,400,20);
JTextArea area=new JTextArea("");  
area.setBounds(00,60, 400,440);  

          
f.add(b);//adding button in JFrame  
f.add(b1);//adding button in JFrame  
f.add(t1);
f.add(area);  
          
f.setSize(413,500);//400 width and 500 height  
f.setLayout(null);//using no layout managers  
f.setVisible(true);//making the frame visible  

b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){  
        try {
            FileWriter myWriter = new FileWriter(t1.getText());
            myWriter.write(area.getText());
            myWriter.close();
            System.out.println("Successfully wrote to the file.");
            Runtime.getRuntime().exec("cmd /c start save.vbs /K");
          } catch (IOException f) {
            System.out.println("An error occurred.");
            try {
                Runtime.getRuntime().exec("cmd /c start error.vbs /K");
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            f.printStackTrace();
          }
    }  
    
    });

    b1.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){  
            try {
                File myObj = new File(t1.getText());
                Scanner myReader = new Scanner(myObj);
                while (myReader.hasNextLine()) {
                  String data = myReader.nextLine();
                  area.setText(data);
                }
                myReader.close();
                Runtime.getRuntime().exec("cmd /c start load.vbs /K");
              } catch (FileNotFoundException f) {
                System.out.println("An error occurred.");
                try {
                    Runtime.getRuntime().exec("cmd /c start error.vbs /K");
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                f.printStackTrace();
              } catch (IOException e1) {
                e1.printStackTrace();
            }
        }  
        
        });
}  

}  
